package com.atguigu.crowd.mvc.handler;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.atguigu.crowd.entity.Admin;
import com.atguigu.crowd.service.api.AdminService;
import com.atguigu.crowd.util.CrowdUtil;

@Controller
public class TestHandler {

    private static Logger logger = LoggerFactory.getLogger(TestHandler.class);
    
    @Autowired AdminService adminService;
    
    @ResponseBody
    @RequestMapping("/test/ajax/async")
    public String testAsync() {
        return "success";
    }
    
    /*// 测试复杂json数据
    @ResponseBody
    @RequestMapping("send/compose/object.json")
    public ResultEntity<Student> testReceiveComposeObject(@RequestBody Student student, HttpServletRequest request) {
        boolean judgeResult = CrowdUtil.judgeRequestType(request);
        logger.info("judgeResult=" + judgeResult);
        
        String a = null;
        System.out.println(a.length());
        
        logger.info(student.toString());
        logger.info(student.getSubjectList().toString());
        // 将”查询“到是student对象封装到ResultEntity中返回
        ResultEntity<Student> resultEntity = ResultEntity.successWithData(student);
        return resultEntity;
    }
    */
    
    @ResponseBody
    @RequestMapping("send/array/three.html")
    public String testReceiveArrayThree(@RequestBody List<Integer> array) {
        
        for(Integer number:array) {
            logger.info("number=" + number);
        }
        return "success";
    }
    
    @RequestMapping("/test/ssm.html")
    public String testSsm(ModelMap modelMap, HttpServletRequest request) {
        boolean judgeResult = CrowdUtil.judgeRequestType(request);
        logger.info("judgeResult=" + judgeResult);
        
        List<Admin> adminList = adminService.getAll();
        modelMap.addAttribute("adminList",adminList);
        
         System.out.println(10/0);
//        String a = null;
//        System.out.println(a.length());
        
        return "target";
    }
    
    @ResponseBody
    @RequestMapping("send/array/one.html")
    public String testReceiveArrayOne(@RequestParam("array[]") List<Integer> array) {
        for(Integer number:array) {
            System.out.println("number=" + number);
        }
        return "success";
    }
}
